﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using nERP.Model.Po;
using nERP.Model;
using nERP.Model.Bas;
using nERP.Model.Wms;

namespace nERP.ViewModel.Po.BuyReturnDetailVMs
{
    public partial class BuyReturnDetailListVM : BasePagedListVM<BuyReturnDetail_View, BuyReturnDetailSearcher>
    {

        protected override IEnumerable<IGridColumn<BuyReturnDetail_View>> InitGridHeader()
        {
            return new List<GridColumn<BuyReturnDetail_View>>{

                this.MakeGridHeader(x => x.BuyReturnDetail_Seq).SetTitle(@Localizer["Page.序号"].Value),
                this.MakeGridHeader(x => x.BuyReturnDetail_BuyReturn).SetTitle(@Localizer["Page.采购退货"].Value),
                this.MakeGridHeader(x => x.BuyReturnDetail_BuyReturnDetailCode).SetTitle(@Localizer["Page.采购退货明细单号"].Value),
                this.MakeGridHeader(x => x.BuyReturnDetail_BuyInWarehouseDetail).SetTitle(@Localizer["Page.采购入库明细"].Value),
                this.MakeGridHeader(x => x.BuyReturnDetail_Buy).SetTitle(@Localizer["Page.采购"].Value),
                this.MakeGridHeader(x => x.BuyReturnDetail_BuyDatail).SetTitle(@Localizer["Page.采购明细"].Value),
                this.MakeGridHeader(x => x.BuyReturnDetail_Goods).SetTitle(@Localizer["Page.商品"].Value),
                this.MakeGridHeader(x => x.BuyReturnDetail_GoodsName).SetTitle(@Localizer["Page.商品名称"].Value),
                this.MakeGridHeader(x => x.BuyReturnDetail_GoodsSpec).SetTitle(@Localizer["Page.商品规格"].Value),
                this.MakeGridHeader(x => x.BuyReturnDetail_GoodsUnit).SetTitle(@Localizer["Page.商品单位"].Value),
                this.MakeGridHeader(x => x.BuyReturnDetail_ReturnNumber).SetTitle(@Localizer["Page.退货数量"].Value),
                this.MakeGridHeader(x => x.BuyReturnDetail_UnitPrice).SetTitle(@Localizer["Page.退货单价"].Value),
                this.MakeGridHeader(x => x.BuyReturnDetail_DiscountPrice).SetTitle(@Localizer["Page.折扣价格"].Value),
                this.MakeGridHeader(x => x.BuyReturnDetail_TotalPrice).SetTitle(@Localizer["Page.退货金额"].Value),
                this.MakeGridHeader(x => x.BuyReturnDetail_TaxRate).SetTitle(@Localizer["Page.税率"].Value),
                this.MakeGridHeader(x => x.BuyReturnDetail_TaxUnitPrice).SetTitle(@Localizer["Page.含税单价"].Value),
                this.MakeGridHeader(x => x.BuyReturnDetail_TaxPrice).SetTitle(@Localizer["Page.税额"].Value),
                this.MakeGridHeader(x => x.BuyReturnDetail_TotalTaxPrice).SetTitle(@Localizer["Page.含税金额"].Value),
                this.MakeGridHeader(x => x.BuyReturnDetail_Remark).SetTitle(@Localizer["_Admin.Remark"].Value),
                this.MakeGridHeader(x => x.BuyReturnDetail_Status).SetTitle(@Localizer["Page.状态"].Value),
                this.MakeGridHeader(x => x.BuyReturnDetail_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.BuyReturnDetail_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.BuyReturnDetail_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.BuyReturnDetail_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }


        public override IOrderedQueryable<BuyReturnDetail_View> GetSearchQuery()
        {
            var query = DC.Set<BuyReturnDetail>()

                .CheckEqual(Searcher.Seq, x => x.Seq)
                .CheckEqual(Searcher.BuyReturnId, x => x.BuyReturnId)
                .CheckContain(Searcher.BuyReturnDetailCode, x => x.BuyReturnDetailCode)
                .CheckEqual(Searcher.BuyInWarehouseDetailId, x => x.BuyInWarehouseDetailId)
                .CheckEqual(Searcher.BuyId, x => x.BuyId)
                .CheckEqual(Searcher.BuyDatailId, x => x.BuyDatailId)
                .CheckEqual(Searcher.GoodsId, x => x.GoodsId)
                .CheckContain(Searcher.GoodsName, x => x.GoodsName)
                .CheckContain(Searcher.GoodsSpec, x => x.GoodsSpec)
                .CheckContain(Searcher.GoodsUnit, x => x.GoodsUnit)
                .CheckEqual(Searcher.ReturnNumber, x => x.ReturnNumber)
                .CheckEqual(Searcher.UnitPrice, x => x.UnitPrice)
                .CheckEqual(Searcher.DiscountPrice, x => x.DiscountPrice)
                .CheckEqual(Searcher.TotalPrice, x => x.TotalPrice)
                .CheckEqual(Searcher.TaxRate, x => x.TaxRate)
                .CheckEqual(Searcher.TaxUnitPrice, x => x.TaxUnitPrice)
                .CheckEqual(Searcher.TaxPrice, x => x.TaxPrice)
                .CheckEqual(Searcher.TotalTaxPrice, x => x.TotalTaxPrice)
                .CheckContain(Searcher.Remark, x => x.Remark)
                .CheckEqual(Searcher.Status, x => x.Status)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x => x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x => x.UpdateBy)
                .Select(x => new BuyReturnDetail_View
                {
                    ID = x.ID,

                    BuyReturnDetail_Seq = x.Seq,
                    BuyReturnDetail_BuyReturn = DC.Set<BuyReturn>().Where(z0 => z0.BuyReturnCode == x.BuyReturnId).Select(y => y.BuyReturnCode).FirstOrDefault(),
                    BuyReturnDetail_BuyReturnDetailCode = x.BuyReturnDetailCode,
                    BuyReturnDetail_BuyInWarehouseDetail = DC.Set<BuyInWarehouseDetail>().Where(z0 => z0.BuyInWarehouseDetailCode == x.BuyInWarehouseDetailId).Select(y => y.BuyInWarehouseDetailCode).FirstOrDefault(),
                    BuyReturnDetail_Buy = DC.Set<Buy>().Where(z0 => z0.BuyCode == x.BuyId).Select(y => y.BuyCode).FirstOrDefault(),
                    BuyReturnDetail_BuyDatail = DC.Set<BuyDetail>().Where(z0 => z0.BuyDetailCode == x.BuyDatailId).Select(y => y.BuyDetailCode).FirstOrDefault(),
                    BuyReturnDetail_Goods = x.GoodsId,//DC.Set<Goods>().Where(z0 => z0.GoodsCode == x.GoodsId).Select(y => y.GoodsName).FirstOrDefault(),
                    BuyReturnDetail_GoodsName = x.GoodsName,
                    BuyReturnDetail_GoodsSpec = x.GoodsSpec,
                    BuyReturnDetail_GoodsUnit = x.GoodsUnit,
                    BuyReturnDetail_ReturnNumber = x.ReturnNumber,
                    BuyReturnDetail_UnitPrice = x.UnitPrice,
                    BuyReturnDetail_DiscountPrice = x.DiscountPrice,
                    BuyReturnDetail_TotalPrice = x.TotalPrice,
                    BuyReturnDetail_TaxRate = x.TaxRate,
                    BuyReturnDetail_TaxUnitPrice = x.TaxUnitPrice,
                    BuyReturnDetail_TaxPrice = x.TaxPrice,
                    BuyReturnDetail_TotalTaxPrice = x.TotalTaxPrice,
                    BuyReturnDetail_Remark = x.Remark,
                    BuyReturnDetail_Status = x.Status,
                    BuyReturnDetail_CreateTime = x.CreateTime,
                    BuyReturnDetail_UpdateTime = x.UpdateTime,
                    BuyReturnDetail_CreateBy = x.CreateBy,
                    BuyReturnDetail_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }


    }
    public class BuyReturnDetail_View : BuyReturnDetail
    {

        public int? BuyReturnDetail_Seq { get; set; }
        public string BuyReturnDetail_BuyReturn { get; set; }
        public string BuyReturnDetail_BuyReturnDetailCode { get; set; }
        public string BuyReturnDetail_BuyInWarehouseDetail { get; set; }
        public string BuyReturnDetail_Buy { get; set; }
        public string BuyReturnDetail_BuyDatail { get; set; }
        public string BuyReturnDetail_Goods { get; set; }
        public string BuyReturnDetail_GoodsName { get; set; }
        public string BuyReturnDetail_GoodsSpec { get; set; }
        public string BuyReturnDetail_GoodsUnit { get; set; }
        public decimal? BuyReturnDetail_ReturnNumber { get; set; }
        public decimal? BuyReturnDetail_UnitPrice { get; set; }
        public decimal? BuyReturnDetail_DiscountPrice { get; set; }
        public decimal? BuyReturnDetail_TotalPrice { get; set; }
        public decimal? BuyReturnDetail_TaxRate { get; set; }
        public decimal? BuyReturnDetail_TaxUnitPrice { get; set; }
        public decimal? BuyReturnDetail_TaxPrice { get; set; }
        public decimal? BuyReturnDetail_TotalTaxPrice { get; set; }
        public string BuyReturnDetail_Remark { get; set; }
        public dStatusTypeEnum? BuyReturnDetail_Status { get; set; }
        public DateTime? BuyReturnDetail_CreateTime { get; set; }
        public DateTime? BuyReturnDetail_UpdateTime { get; set; }
        public string BuyReturnDetail_CreateBy { get; set; }
        public string BuyReturnDetail_UpdateBy { get; set; }

    }

}